import request from "@/utils/request";
import store from "@/store/index";
/**
 * 判断当前用户是否为租户
 *
 * @returns {boolean} 当前用户是否为租户
 */
export function isTenant() {
  return !!store.getters.userInfo.tenantId;
}
/**
 * 获取应用版本码
 *
 * @returns {string} 应用版本码
 */
export function appVerCode() {
  return store?.getters?.userInfo?.chooseAppVerCode;
}
/**
 * 获取事件上下文
 *
 * @returns {string} 返回事件上下文字符串
 */
function eventContext() {
  return isTenant() ? "/event" : "/ttevent";
}
/**
 * 设备上下文
 *
 * @returns {string} 返回设备上下文路径
 */
function deviceContext() {
  return isTenant() ? "/device" : "/ttdevice";
}

/**
 * 获取 BDM 上下文路径
 *
 * @returns {string} BDM 上下文路径
 */
function bdmContext() {
  return isTenant() ? "/bdm" : "/ttbdm";
}

let alarmEvent_allAreaCode = "";

/*查询图层-站址 */
export function querySitesForWE(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + "/video/device/querySitesForWE",
    method: "post",
    data,
  });
}
export function querySiteCodeAndDevices(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + "/video/device/querySiteCodeAndDevices",
    method: "post",
    data,
  });
}
/*查询图层-告警 */
export function searchOrderNumByLongitude(data) {
  return request({
    url: eventContext() + "/alarm/order/searchOrderNumByLongitude",
    method: "post",
    data,
  });
}
/**
 * 选择图层网格
 */
export function getGridListByLayer(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: bdmContext() + "/grid/getGridListByLayer",
    method: "post",
    data,
  });
}
/**
 * 选择图层网格员
 */
export function getGridKeeperByLayer(data) {
  return request({
    url: bdmContext() + "/gridKeeper/getGridKeeperByLayer",
    method: "post",
    data,
  });
}

/**
 * 选择图层网格员 新接口
 * 在一个网格员对应多个网格的情况下去重网格员
 */
export function getGridKeeperByLayerNew(data) {
  return request({
    url: bdmContext() + "/gridKeeper/getGridKeeperByLayerNew",
    method: "post",
    data,
  });
}

/* 查询摄像机列表接口*/
export function queryDevices(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + "/video/device/queryDevices",
    method: "post",
    data,
  });
}
/* 查询显示资源详情*/
export function getResourceInfo(data) {
  return request({
    url: `/bdm/resource/getResourceInfo?resourceId=${data}`,
    method: "get",
  });
}

/*查询告警列表 */
export function searchOrderListByLongitude(data) {
  return request({
    url: `${eventContext()}/alarm/order/searchOrderListByLongitude?pageSize=${
      data.pageSize
    }&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}
/*查询显示网格员详情 */
export function findOne(data) {
  return request({
    url: `${bdmContext()}/gridKeeper/findOne?keeperId=${data}`,
    method: "get",
  });
}
/*查询摄像机信息 */
export function queryDeviceForWE(data) {
  return request({
    url: deviceContext() + "/video/device/queryDeviceForWE",
    method: "post",
    data,
  });
}
//获取设备标签---铁塔
export function queryVideoDetailTower(query) {
  let url = "/video/queryVideoDetail";
  if (isTenant()) {
    url = "/video/device/queryDeviceForWE";
  }
  return request({
    url: deviceContext() + url,
    method: "post",
    data: query,
  });
}
/*获取省市区数量打点数据 */
export function getNumForScreen(data) {
  return request({
    url: eventContext() + "/geo/getNumForScreen",
    method: "post",
    data,
  });
}
/* 查询周边接口和图层接口*/
export function queryList(data) {
  return request({
    url: `${bdmContext()}/resource/selectResource`,
    method: "post",
    data,
  });
}
/* 查询周边接口和图层接口（分页）*/
export function queryPage(data) {
  return request({
    url: `${bdmContext()}/resource/selectResourceConfList`,
    method: "post",
    data,
  });
}
/* 查询告警列表接口*/
export function getOrderListForBigScreen(data) {
  return request({
    url: `${eventContext()}/alarm/order/getOrderListForBigScreen?pageSize=${
      data.pageSize
    }&pageNum=${data.pageNum}`,
    method: "post",
    data,
  });
}

/*获取省份列表*/
export function getArea() {
  if (!alarmEvent_allAreaCode) {
    alarmEvent_allAreaCode = new Promise((resolve) => {
      request({
        url: "/admin/system/area/queryAllAreaCode",
        method: "get",
      }).then((res) => {
        resolve(res);
      });
    });
  }
  return alarmEvent_allAreaCode;
}
/*根据经纬度查询地市*/
export function lnglat2Geo(data) {
  return request({
    url: `/gis/gis/countryAreaQuery`,
    method: "post",
    data,
  });
}
/*根据区域编码查询经纬度 */
export function getLatitude(data) {
  return request({
    url: "gis/gis/getLatitude",
    method: "post",
    data,
  });
}
/*获取租户摄像头订购级别 */
export function getTenantMonitorLevel(data) {
  if (isTenant()) {
    data.appVerCode = appVerCode();
  }
  return request({
    url: deviceContext() + "/video/getTenantMonitorLevel",
    method: "post",
    data,
  });
}
/*获取铁塔用户级别 */
export function getTTLevel(data) {
  return request({
    url: "/ttdevice/video/getTTLevel",
    method: "post",
    data,
  });
}

/*查询事件热力图统计 */
export function getThermDiagramNum(data) {
  return request({
    url: "analysis/video/getThermDiagramNum",
    method: "post",
    data,
  });
}
/*查询客户信息 */
export function queryUserInfo(data) {
  return request({
    url: `/admin/system/user/base/detail/${data}`,
    method: "get",
  });
}
/* 获取登录信息 */
export function queryTenantLabelList(data) {
  return request({
    url: deviceContext() + "/video/device/queryTenantLabelList",
    method: "post",
    data,
  });
}

export function queryDeviceLabelInfoByDeviceCode(data) {
  return request({
    url: "/device/video/device/queryDeviceLabelInfoByDeviceCode",
    method: "post",
    data,
  });
}

/*根据经纬度查询地市*/
export function codeToAdress(data) {
  return request({
    url: `/gis/gis/codeToAdress`,
    method: "post",
    data,
  });
}

// 运营研判 获取图斑信息
export function getPolygonOperate(data) {
  let url = "";
  if (isTenant()) {
    url = `ttevent/alarm/order/operate/getPolygonOperate`;
  } else {
    url = `event/alarm/order/getPolygonOperate`;
  }
  return request({
    url: url,
    data: data,
    method: "post",
  });
}

//获取行政区划名称
export function districtQuery(data) {
  return request({
    url: "gis/gis/districtQuery",
    data: data,
    method: "post",
  });
}
// 获取周边信息列表
export function getAroundAnalysisOwnList(data) {
  return request({
    url: `${bdmContext()}/aroundAnalysisOwn/getAroundAnalysisOwnList `,
    method: "post",
    data,
  });
}
//实时喊话-开始喊话 （获取锁以及播发）
export function startTalk(data) {
  return request({
    url: `/device/hornDevice/startTalk`,
    method: "post",
    data,
  });
}
//实时喊话-停止（释放锁及停止播放）
export function stopTalk(data) {
  return request({
    url: `/device/hornDevice/stopTalk`,
    method: "post",
    data,
  });
}
